home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / program / ixemlsrc.lha / ixemul / library / __wait_packet.c < prev    next >
C/C++ Source or Header  |  1995-12-23  |  3KB  |  124 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  __wait_packet.c,v 1.1.1.1 1994/04/04 04:30:14 amiga Exp
  20.  *
  21.  *  __wait_packet.c,v
  22.  * Revision 1.1.1.1  1994/04/04  04:30:14  amiga
  23.  * Initial CVS check in.
  24.  *
  25.  *  Revision 1.3  1992/07/04  19:08:41  mwild
  26.  *  change to new ix_sleep format, add wmesg-string
  27.  *
  28.  * Revision 1.2  1992/05/18  11:58:15  mwild
  29.  * use dp_Port field, NT_REPLYMSG is not reliable
  30.  *
  31.  * Revision 1.1  1992/05/14  19:55:40  mwild
  32.  * Initial revision
  33.  *
  34.  */
  35.  
  36. #define KERNEL
  37. #include "ixemul.h"
  38. #include "kprintf.h"
  39. #include <signal.h>
  40.  
  41.  
  42. /* I'm using dp_Port as an indicator whether this packet is
  43.    free. If in use, this field can't be 0. */
  44. #define PACKET_IN_USE(sp) (sp->sp_Pkt.dp_Port)
  45.  
  46. /*
  47.  * ^F is a bail-out, if something really goes weird.. 
  48.  */
  49.  
  50. #define SIGMASK ((1<<u.u_sync_mp->mp_SigBit) | SIGBREAKF_CTRL_F)
  51.  
  52. void
  53. __wait_sync_packet(struct StandardPacket *sp)
  54. {
  55.   struct StandardPacket *prw;
  56.   int omask;
  57.  
  58.   /* this is the synchronous way of dealing with packets that may
  59.    * arrive at a port. */
  60.  
  61.   if (! PACKET_IN_USE (sp)) return;
  62.  
  63.   omask = syscall (SYS_sigsetmask, ~0);
  64.  
  65.   for (;;)
  66.     {
  67.       if ((prw = GetPacket(u.u_sync_mp)))
  68.         {
  69.       PACKET_IN_USE (prw) = 0;
  70.           if (prw == sp) break;
  71.         }
  72.       else
  73.         {
  74.       unsigned long res;
  75.  
  76.       res = Wait(SIGMASK);
  77.       /* process our bail-out-signal */
  78.       if (res & SIGBREAKF_CTRL_F) break;
  79.     }
  80.     }
  81.   
  82.   syscall (SYS_sigsetmask, omask);
  83. }
  84.  
  85.  
  86. void
  87. __wait_packet(struct StandardPacket *sp)
  88. {
  89.   int rc = 0;
  90.  
  91.   /* have to make sure no interrupt is taken between we test and
  92.    * call ix_sleep(), or ix_sleep() will never be awakend..
  93.    * ix_sleep() calls Wait(), and thus breaks the Disable() */
  94.   while (PACKET_IN_USE (sp))
  95.     {
  96.       KPRINTF (("__wait_packet - "));
  97.       Disable ();
  98.       if (PACKET_IN_USE (sp))
  99.         rc = ix_sleep ((caddr_t)sp, "wait_packet");
  100.       Enable ();
  101.       if (rc < 0)
  102.         /* take any outstanding signals, or ix_sleep will never really sleep.. */
  103.         setrun (FindTask (0));
  104.     }
  105. }
  106.  
  107.  
  108. void mp_interrupt (void)
  109. {
  110.   register struct MsgPort *_mp asm ("a1");
  111.   register struct MsgPort *mp = _mp;
  112.   register struct StandardPacket *prw;
  113.   
  114.   Disable ();
  115.   while ((prw = GetPacket (mp)))
  116.     {
  117.       PACKET_IN_USE (prw) = 0;
  118.  
  119.       /* wakeup any processes that might be interested in this packet */
  120.       ix_wakeup ((u_int)prw);
  121.     }
  122.   Enable ();
  123. }
  124.